﻿using INTEX.DataBase.Tools;
using ReflectionStudio.Core.Events;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using WPFExcelReport;
namespace Intex.Tools
{
    public class IntexTools : BaseFunction
    {
        ApplicationBase app
        {
            get
            {
                return ApplicationBase.Instance;
            }
        }
        INTEXDBC INTEXDBC
        {
            get
            {
                return app.INTEXDBC;
            }
        } 
        public IntexTools()
            : base()
        {

        }
        public IntexTools(Dictionary<string, object> DicGlobalPara)
            : base(DicGlobalPara)
        {
        }
        public IntexTools(OracleConnection _myConnection, IntexReptServBLClient _proxy, string userID = "        ")
            : base(_myConnection, _proxy, userID)
        {
           
        }
        public string GetABAUFM(string ftype,string art, string var, string color, string finish)
        {
            DataSet result = new DataSet();
            string Return=null;
            string VAR = Right("   " + var, 3);
            try
            {
                orlReadCommand = OracleDB.CreateCommand();
                orlReadCommand.CommandText = "SELECT DISTINCT ABAETITYP FROM ABAUFM A JOIN ABPOS P ON ABAMANDANT=ABPMANDANT AND ABAAUFKRS=ABPAUFKRS AND ABAAUFLFD=ABPAUFLFD AND ABAAUFPOS=ABPAUFPOS"
                    + " WHERE ABPWAKZ=:ABPWAKZ AND ABPART = :ABPART AND ABPVAR=:ABPVAR AND ABPFARBE=:ABPFARBE AND ABPBESCHICH=:ABPBESCHICH"
                    +" ORDER BY 1 DESC";
                orlReadCommand.Parameters.Add("ABPWAKZ", OracleType.NVarChar).Value = ftype;
                orlReadCommand.Parameters.Add("ABPART", OracleType.NVarChar).Value = art;
                orlReadCommand.Parameters.Add("ABPVAR", OracleType.NVarChar).Value = VAR;
                orlReadCommand.Parameters.Add("ABPFARBE", OracleType.NVarChar).Value = color;
                orlReadCommand.Parameters.Add("ABPBESCHICH", OracleType.NVarChar).Value = finish;
                setResult = INTEXDBC.Connect2Proxy(orlReadCommand);
                if (setResult.Tables.Count > 0)
                {
                    foreach (DataRow dwTemp in setResult.Tables[0].Rows)
                    {
                        Return = dwTemp["ABAETITYP"].ToString();
                        break;
                    }
                } 
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }

            return Return;
        }
    }
}
